package basic.study.leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName Mid94
 * @Description 二叉树的中序遍历
 * @Company inspur
 * @Author Kevin
 * @Date 2020/6/25 16:41
 * @Version 1.0
 */
public class Mid94 {
    class Solution {
        public List<Integer> inorderTraversal(TreeNode root) {
            List<Integer> res = new ArrayList<>();
            helper(root, res);
            return res;
        }

        private void helper(TreeNode root, List<Integer> res) {
            if (root == null) return;

            if (root.left != null) {
                helper(root.left, res);
            }
            res.add(root.val);
            if (root.right != null) {
                helper(root.right, res);
            }
        }
    }

    static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode(int x) {
            val = x;
        }
    }
}
